package com.zxm.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GatewayConfig {
    @Bean
    public RouteLocator CustomRouteLocator(RouteLocatorBuilder routeLocatorBuilder){
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes(); //类似于yml中的routes
        /**
         * path_route_zxm"相当于yml中routes下的id
         * r -> r.path("/guonei")
         *        .uri("http://news.baidu.com/guonei")).build();
         *  表示你访问9527/guonei，会转发到
         *  http://news.baidu.com/guonei
         */
        routes.route("path_route_zxm",
                r -> r.path("/guonei")
                        .uri("http://news.baidu.com/guonei")).build();
        return routes.build();
    }
}
